/**   
 * @Title: SplitHelper.java 
 * @Package com.kunpu.framework.commons.page 
 * @Description: 分页组件操作类
 * @author wangtq
 * @date 2016年10月5日 
 * @version V1.0   
 */
package com.kunpu.framework.commons.page;

import java.util.Map;


/**
 * @ClassName: SplitHelper
 * @Description: 业务操作工具类
 * @author wangtq
 * @date 2016年10月5日 
 */
public class SplitHelper {
	public static void pubMapforSplitPage(SplitPageRequest request,
			Map<String, Object> map) {
		map.put("rowStart", getRowStart(request));
		map.put("rowCount", getRowCount(request));
	}

	public static int getRowStart(SplitPageRequest request) {
		if (request != null) {
			return (request.getPageNo() - 1) * request.getPageSize();
		} else {
			return 0;
		}
	}

	public static int getRowCount(SplitPageRequest request) {
		if (request != null && request.getPageSize()>0) {
			return request.getPageSize();
		} else {
			return 20;
		}
	}

	public static SplitPageResponse getSplitPageResponse(int rowCount,
			int pageSize, int pageNo) {
		int pageCount = 1;
		if (pageSize <= 0) {
			pageSize = 20;
		}
		SplitPageResponse response = new SplitPageResponse();
		pageCount = (int) Math.ceil((double) rowCount / pageSize);
		response.setPageCount(pageCount);
		response.setRecordCount(rowCount);
		if (pageNo <= 0) {
			pageNo = 1;
		}
		response.setPageNo(pageNo);
		return response;
	}

	
}
